#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/int32.hpp"

class SentinelNode : public rclcpp::Node {
public:
    SentinelNode() : Node("sentinel_node") {
        subscription_ = this->create_subscription<std_msgs::msg::Int32>(
            "_time", 10, std::bind(&SentinelNode::topic_callback, this, std::placeholders::_1));
    }

private:
    void topic_callback(const std_msgs::msg::Int32::SharedPtr msg) const {
        int time_seconds = msg->data;
        if (time_seconds >= 0 && time_seconds < 20) {
            RCLCPP_INFO(this->get_logger(), "位于前哨站");
        } else if (time_seconds >= 20 && time_seconds < 40) {
            RCLCPP_INFO(this->get_logger(), "位于基地");
        } else if (time_seconds >= 40 && time_seconds < 60) {
            RCLCPP_INFO(this->get_logger(), "位于补给区");
        }
    }
    rclcpp::Subscription<std_msgs::msg::Int32>::SharedPtr subscription_;
};

int main(int argc, char *argv[]) {
    rclcpp::init(argc, argv);
    rclcpp::spin(std::make_shared<SentinelNode>());
    rclcpp::shutdown();
    return 0;
}
